package com.stephenone.zhdaily.homepage.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.stephenone.zhdaily.R;
import com.stephenone.zhdaily.uitl.DateHelper;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by Administrator on 2018/1/29.
 */

public class DateViewBinder extends ItemViewBinder<String,DateViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_date, parent,
                false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull String item) {
        if (DateHelper.isToday(item)) {
            item = "今天";
        }else {
            item = DateHelper.getSpokenDate(item) + " " + DateHelper.getWeek(item);
        }
        holder.mDateTextView.setText(item);
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView mDateTextView;
        public ViewHolder(View itemView) {
            super(itemView);
            mDateTextView = itemView.findViewById(R.id.tv_date);
        }
    }
}
